<?php

include_once("DB.php");

class MVC_Model {
    var $result;
    var $db;

    function MVC_Model() {
        // db connection here
        $dsn = DB_URL;
        $this->db = DB::connect(DB_URL);
        if (DB::isError($this->db)) {
            trigger_error($this->db->getMessage(), E_USER_ERROR);
        }
        $this->db->setFetchMode(DB_FETCHMODE_ASSOC);
        $this->result = null;
    }

    function query($sql, $data=null)
    {
        return $this->db->query($sql, $data);
    }
    
    function getOne($sql, $data=null)
    {
        return $this->db->getOne($sql, $data);
    }
    
    function getRow($sql, $data=null)
    {
        return $this->db->getRow($sql, $data);
    }
    
    function getCol($sql, $data=null)
    {
        return $this->db->getCol($sql, $data);
    }

    function getAll($sql, $data=null)
    {
        return $this->db->getAll($sql, $data);
    }

    function fetchToArray() {
        $result_array = array();
        while($row = $this->result->fetchRow(DB_FETCHMODE_ASSOC) ) {
            $result_array[] = $row;
        }
        return $result_array;
    }
}


?>
